function showOrg() {
    $.ajax({
        url: '/class/show',
        data: {
            count: count, //每页显示条数
            page: page //当前页码
        },
        success: (res) => {
            if (res.error) {
                console.log(res.error);
            } else {
                $('#cont_table tbody').html('');
                $(res.data).each((index, item) => {
                    $('#cont_table tbody').append(`
                    <tr data-id="${item.c_id}">
                        <th>
                            <div class="checkbox">
                                <label>
                                <input type="checkbox" value="option1" aria-label="...">
                                </label>
                            </div>
                        </th>
                        <th>${item.c_id}</th>
                        <th>${item.c_name}</th>
                        <th>${item.m_name}</th>
                        <th>${item.m_teacher}</th>
                        <th>${item.d_name}</th>
                        <th>${item.m_describe}</th>
                        <th><button class="btn_com btn_frameless" data-cont='${JSON.stringify(item)}'><span class="iconfont icon-pen"></span>编辑</button><button class="btn_del btn_frameless"><span class="iconfont icon-lajitong"></span>删除</button></th>
                    </tr>   
                    `)
                });
                $('.pagination').html(`     
                <li id="page_left">
                    <a href="#" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
                <li id="page_right">
                    <a href="#" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
                `);
                maxPage = Math.ceil((res.total / count));
                page > maxPage ? page = maxPage : page = page;
                paging($('#page_right'), maxPage, page);
            }
        }
    })
}


// 获取下拉框输入的值，查询内容
function inquire() {
    $('#content').on('click', '.btn_que', function() {
        $.ajax({
            url: '/class/que',
            method: 'post',
            data: {
                val1: $('#sel_1').val(),
                val2: $('#sel_2').val(),
                val3: $('#sel_3').val(),
            },

            success: (res) => {
                if (res.error) {
                    console.log(res.error);
                } else {
                    $('#cont_table tbody').html('');
                    $(res.data).each((index, item) => {
                        $('#cont_table tbody').append(`
                        <tr data-id="${item.c_id}">
                            <th>
                                <div class="checkbox">
                                    <label>
                                    <input type="checkbox" value="option1" aria-label="...">
                                    </label>
                                </div>
                            </th>
                            <th>${item.c_id}</th>
                            <th>${item.c_name}</th>
                            <th>${item.m_name}</th>
                            <th>${item.m_teacher}</th>
                            <th>${item.d_name}</th>
                            <th>${item.m_describe}</th>
                            <th><button class="btn_com btn_frameless" data-cont='${JSON.stringify(item)}'><span class="iconfont icon-pen"></span>编辑</button><button class="btn_del btn_frameless"><span class="iconfont icon-lajitong"></span>删除</button></th>
                        </tr>   
                        `)
                    });
                    $('.pagination').html(`     
                    <li id="page_left">
                        <a href="#" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
                    <li id="page_right">
                        <a href="#" aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>
                    `);
                    maxPage = Math.ceil((res.total / count));
                    page > maxPage ? page = maxPage : page = page;
                    paging($('#page_right'), maxPage, page);
                }
            }
        });
    })
}
let bVal = '';
// 渲染下拉
function showSel() {
    $.ajax({
        url: '/class/showsel_department',
        success: (res) => {
            $('#sel_1').html('<option value="" selected disabled class="sel_none">学院名称</option>');
            $(res.data).each((index, item) => {
                $('#sel_1').append(`    
            <option value="${item.d_name}">${item.d_name}</option>`);
            })
        }
    })
}

// 渲染下拉
function showSel2() {
    $.ajax({
        url: '/class/showsel_major',
        method: 'get',
        data: {
            val: bVal
        },
        success: (res) => {
            $('#sel_2').html('<option value="" selected disabled class="sel_none">选择专业名称</option>');
            $(res.data).each((index, item) => {
                $('#sel_2').append(`    
                <option value="${item.m_name}">${item.m_name}</option>`);
            })
        }
    })
}

function showSel3() {
    $.ajax({
        url: '/class/showsel_class',
        method: 'get',
        data: {
            val: bVal
        },
        success: (res) => {
            if (res.data.length) {
                $('#sel_3').html('<option value="" selected disabled class="sel_none">选择班级</option>');
                $(res.data).each((index, item) => {
                    $('#sel_3').append(`    
                    <option value="${item.c_name}">${item.c_name}</option>`);
                })
            }
        }
    })
}

function showSel4() {
    $.ajax({
        url: '/class/showsel_class_m_id',
        method: 'get',
        data: {
            val: bVal
        },
        success: (res) => {
            if (res.data.length) {
                $('#sel_6').attr({ value: `${res.data[0].m_id}` })
            }
        }
    })
    $.ajax({
        url: '/class/showsel_class_m_id',
        method: 'get',
        data: {
            val: bVal
        },
        success: (res) => {
            if (res.data.length) {
                $('#sel_4').attr({ value: `${res.data[0].m_teacher}` })
            }
        }
    })
}


$('#sel_1').click(function() {
    bVal = $(this).val();
    showSel2();
    showSel3();
})
$('#sel_2').click(function() {
    bVal = $(this).val();
    showSel3();
    showSel4();
})

// 创建的职位管理的新数据
function selVal() {
    $('.btn_new').click(function() {
        if (confirm('是否确定创建？')) {
            $.ajax({
                url: '/class/selVal',
                method: 'post',
                data: {
                    c_m_id: $('#sel_6').val(),
                    c_name: $('#sel_5').val(),
                },
                success: (res) => {
                    if (res.error) {
                        console.log(res.msg);
                        alert('带*的内容必须填写!');
                    } else {
                        alert('创建成功!');
                        location.href = "../../pages/zuZhiGuanLi--wangHeng/banJiXuLie.html";
                    }
                }
            })
        }
    })
}

$('.table').on('click', '.btn_com', function() {
    location.href = '../../pages/zuZhiGuanLi--wangHeng/bianJiBanJi.html';
    localStorage.setItem('dataCont', $(this).attr('data-cont'))
})

$('.btn_res').click(function() {
    location.reload();
    console.log(this);
})

//排序
function allSort() {
    $('.sort').click(function() {
        $.ajax({
            url: '/class/sort',
            method: 'post',
            data: {
                sort: $(this).attr('data-sort'),
                order: $(this).attr('data-order'),
                count: count, //每页显示条数
                page: page //当前页码
            },
            success: (res) => {
                if (res.error) {
                    console.log(res.msg);
                } else {
                    $('#cont_table tbody').html('');
                    $(res.data).each((index, item) => {
                        $('#cont_table tbody').append(`
                        <tr data-id="${item.c_id}">
                            <th>
                                <div class="checkbox">
                                    <label>
                                    <input type="checkbox" value="option1" aria-label="...">
                                    </label>
                                </div>
                            </th>
                            <th>${item.c_id}</th>
                            <th>${item.c_name}</th>
                            <th>${item.m_name}</th>
                            <th>${item.m_teacher}</th>
                            <th>${item.d_name}</th>
                            <th>${item.m_describe}</th>
                            <th><button class="btn_com btn_frameless" data-cont='${JSON.stringify(item)}'><span class="iconfont icon-pen"></span>编辑</button><button class="btn_del btn_frameless"><span class="iconfont icon-lajitong"></span>删除</button></th>
                        </tr>   
                        `)
                    });
                    $('.pagination').html(`     
                    <li id="page_left">
                        <a href="#" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
                    <li id="page_right">
                        <a href="#" aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>
                    `);
                    maxPage = Math.ceil((res.total / count));
                    page > maxPage ? page = maxPage : page = page;
                    paging($('#page_right'), maxPage, page);
                    $(this).attr('data-order') == 'ASC' ? $(this).attr('data-order', 'DESC') : $(this).attr('data-order', 'ASC');
                    $(this).attr('data-order') == 'ASC' ? $(this).children().css({ transform: 'rotate(0deg)' }) : $(this).children().css({ transform: 'rotate(180deg)' });
                }
            }
        })
    })
}